<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<title>资源维护</title>
		
		<link rel="stylesheet" type="text/css" href="../css/cm-default.css"  />
		<link rel="stylesheet" type="text/css" href="../ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link rel="stylesheet" type="text/css" href="../ligerUI/skins/ligerui-icons.css" />
		<script src="../js/jquery-min.js" type="text/javascript"></script>
		<script src="../ligerUI/js/ligerui.min.js" type="text/javascript"></script>
		<script src="../js/common.js" type="text/javascript"></script>
		<script src="../js/json2.js" type="text/javascript"></script>
		<script type="text/javascript" src="../js/md5.js"></script>
		
	<script type="text/javascript">
	var defGrid;
	var defGrid2;
	var userid;

        $(function ()
        { 
        	roleid=window.location.toString().replace(/^[^?]+\?roleid=/,'');
        	
        	  defGrid= $("#listbox1").ligerListBox({
                isShowCheckBox: true,
                isMultiSelect: true,
                valueField: 'id',
                textField: 'name',
                valueFieldID: 'test1',
                height: 240
            });
        	var param = new Object();
		    param.roleid=roleid;
            var data = JSON.stringify(reqObj('q','rbac.select.dict.def.queryRoleResouce',JSON.stringify(param)));
            ajaxSubmit("/cmwifi/rbac/cm.do?m=q", data, function(data) {
            	defGrid.set({data: data['data'].Rows});
			},null,false);
			
            defGrid2= $("#listbox2").ligerListBox({
                isShowCheckBox: true,
                isMultiSelect: true,
                valueField: 'id',
                textField: 'name',
                valueFieldID: 'test2',
                height: 240
            });
        	
            var data2 = JSON.stringify(reqObj('q','rbac.select.dict.def.queryRoleResouceyes',JSON.stringify(param)));
            ajaxSubmit("/cmwifi/rbac/cm.do?m=q", data2, function(data) {
            	defGrid2.set({data: data['data'].Rows});
			}, null, false);
        });
        function moveToLeft()
        {
            var box1 = liger.get("listbox1"), box2 = liger.get("listbox2");
         
            var selecteds = box2.getSelectedItems();
            if (!selecteds || !selecteds.length) return;
            box2.removeItems(selecteds);
            box1.addItems(selecteds);
            
            var test2=$("#test2").val();
            //alert(test2);
            if( test2.indexOf(';')<0)
            {
	            var param = new Object();
	            param.roleid=roleid;
				param.resourceid = test2;
				var param = JSON.stringify(reqObj('d','rbac.delete.dict.def.deleRoleResource',JSON.stringify(param)));
					ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
				});
           }
           else
           {
            	var result=test2.split(';');
            	
            	for(var i=0;i<result.length;i++)
                {
                	var param = new Object();
    			    param.resourceid=result[i];
    				param.roleid = roleid;
    				//alert(param.resourceid);
    				var param = JSON.stringify(reqObj('d','rbac.delete.dict.def.deleRoleResource',JSON.stringify(param)));
    					ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
    				});
            	}
           }
        }
        function moveToRight()
        {
            var box1 = liger.get("listbox1"), box2 = liger.get("listbox2");
            var selecteds = box1.getSelectedItems();
            if (!selecteds || !selecteds.length) return;
            box1.removeItems(selecteds);
            box2.addItems(selecteds);
            var test1=$("#test1").val();
           // alert(test1);
            if( test1.indexOf(';')<0)
            {
	            var param = new Object();
	            param.roleid=roleid;
				param.resourceid = test1;
				var data = JSON.stringify(reqObj('a','rbac.add.dict.def.addRoleResourceid',JSON.stringify(param)));
				    ajaxSubmit("/cmwifi/rbac/cm.do?m=a", data, function(data) {
				});
            }
            else
            {
	           	var result=test1.split(';');
	           	for(var i=0;i<result.length;i++)
		        {
		           	var param = new Object();
			        param.roleid=roleid;
			        
				    param.resourceid = result[i];
				    //alert(param.resourceid);
					var data = JSON.stringify(reqObj('a','rbac.add.dict.def.addRoleResourceid',JSON.stringify(param)));
					    ajaxSubmit("/cmwifi/rbac/cm.do?m=a", data, function(data) {
					});
	           	}
            }
        }
        function moveAllToLeft()
        { 
            var box1 = liger.get("listbox1"), box2 = liger.get("listbox2");
            var selecteds = box2.data;
            if (!selecteds || !selecteds.length) return;
            box1.addItems(selecteds);
            box2.removeItems(selecteds); 
            var test2=$("#test2").val();
            alert(test2);
        }
        function moveAllToRight()
        { 
            var box1 = liger.get("listbox1"), box2 = liger.get("listbox2");
            var selecteds = box1.data;
            if (!selecteds || !selecteds.length) return;
            box2.addItems(selecteds);
            box1.removeItems(selecteds);
           
        }
    </script>
    <style type="text/css">
        .middle input {
            display: block;width:30px; margin:2px;
        }
    </style>
</head>
<body style="padding:10px"> 
  
     <div style="margin:4px;float:left;">
     未分配
         <div id="listbox1" ></div>  
     </div>
     <div style="margin:30px;margin-top:24px;float:left;" class="middle">
          
          <input type="button" onclick="moveToRight()" value=">" />
          <input type="button" onclick="moveToLeft()" value="<"  />
         <!--  <input type="button" onclick="moveAllToLeft()" value="<<" />
         <input type="button" onclick="moveAllToRight()" value=">>" /> -->
     </div>
      
    <div style="margin:4px;float:right;">
    已分配
        <div id="listbox2"></div> 
    </div>
</body>
</html>